/**
 * 参数设置类
 */
package com.pms.utils;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.core.io.ClassPathResource;

public class ConfigManage {
	private static ConfigManage config;
	private Map<String, String> configMap = new HashMap<String, String>();

	public static ConfigManage getInstance() {
		if(config==null){
			config =new ConfigManage();
		}
		return config;
	}

	private ConfigManage() {
		loadConfig();
	}

	public String getConfig(String name) {
		return configMap.get(name);
	}

	public void setConfig(String name, String value) {
		configMap.put(name, value);
	}

	public void loadConfig() {
		try {
			ClassPathResource resource = new ClassPathResource(Constant.CONFIG_FILE);
			Properties properties = new Properties();
			properties.load(resource.getInputStream());
			Enumeration<?> en = properties.propertyNames();
			
			while (en.hasMoreElements()) {
				String key = (String) en.nextElement();
				String property = properties.getProperty(key);
				System.out.println(key+"="+property);
				setConfig(key, property);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
